<%@ page import="java.sql.*"%>

<% 
	String newUniversity = request.getParameter("university");
	Connection conn = null;
	PreparedStatement stm = null;
	ResultSet result = null;

	try {
	Class.forName("org.postgresql.Driver");
	conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/Graduate_application_database", "postgres", "postgres");
	conn.setAutoCommit(false);
	stm = conn.prepareStatement("SELECT * FROM universities WHERE university = ? ");
	stm.setString(1, newUniversity);
	result = stm.executeQuery();
	conn.commit();
	conn.setAutoCommit(true);
	boolean resultExists = false;
%>

<% if (result.next()) resultExists = true; //it is there%>

<%=resultExists %> 


<%
	result.close();
	stm.close();
	conn.close();
	}
	catch (Exception e)
	{
		throw new RuntimeException(e);
	}
	finally {
    if (result != null) {
       try {
           result.close();
       } 
       catch (SQLException e) { }
       result = null;
    }
    if (stm != null) {
       try {
           stm.close();
       } 
       catch (SQLException e) { }
       stm = null;
    }
    if (conn != null) {
       try {
           conn.close();
       } 
       catch (SQLException e) { }
       conn = null;
       }
    }
	
%>

